

#include "lcd.h"
#include "FONT.H"
#include "pic.h"
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#include "led.h"

#include "uart_parse.h"
//#include "ds3231.h"
#include "device.h"
#include "jsm1302z.h"
#include "input.h"
#include "tim.h"

#define ESPANOL_VERSION
//#define DEBUG_PRINTF
//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;

//LCD的画笔颜色和背景色
uint16_t POINT_COLOR = 0x0000;  //画笔颜色
uint16_t BACK_COLOR = 0xFFFF; //背景色

uint16_t ColorTab[5] = {RED, GREEN, BLUE, YELLOW, BRED}; //定义颜色数组
uint16_t ColornTab[4] = {RED, GREEN, BLUE};


void LCD_WR_REG(uint8_t data)
{
    SPI_CS_0;
    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)data;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_CS_1;
}
void LCD_WR_DATA(uint8_t data)
{
    SPI_CS_0;
    SPI_DC_1;
    SPI_DATA(SPI1) = (uint32_t)data;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_CS_1;
}


void spi_io_init(uint32_t IS_8BIT)
{
    spi_parameter_struct spi_init_struct;
    spi_disable(SPI1);
    spi_i2s_deinit(SPI1);
    spi_struct_para_init(&spi_init_struct);
    rcu_periph_clock_enable(RCU_GPIOC);
    rcu_periph_clock_enable(RCU_GPIOD);
    gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_0 | GPIO_PIN_1);
    gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0 | GPIO_PIN_1);
    rcu_periph_clock_enable(RCU_GPIOD);
    rcu_periph_clock_enable(RCU_SPI1);
    /* SPI0_CLK(PB3), SPI0_MISO_IO1(PB4), SPI0_MOSI_IO0(PB5),SPI0_IO2(PB6) and SPI0_IO3(PB7) GPIO pin configuration */
    gpio_af_set(GPIOC, GPIO_AF_5, GPIO_PIN_10 | GPIO_PIN_12);
    gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_10 | GPIO_PIN_12);
    //gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_12);
    /* SPI0_CS(PD2) GPIO pin configuration */
    /* chip select invalid */
    //SPI_FLASH_CS_HIGH();
    /* SPI1 parameter config */
    spi_init_struct.trans_mode           = SPI_TRANSMODE_FULLDUPLEX;
    spi_init_struct.device_mode          = SPI_MASTER;
    spi_init_struct.frame_size           = IS_8BIT;//SPI_FRAMESIZE_8BIT;//
    spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE;//
    //spi_init_struct.clock_polarity_phase = SPI_CK_PL_HIGH_PH_1EDGE;//
    //spi_init_struct.clock_polarity_phase = SPI_CK_PL_HIGH_PH_2EDGE;//
    //spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_2EDGE;//
#ifdef HARD_NSS
    spi_init_struct.nss                  = SPI_NSS_HARD;//
#else
    spi_init_struct.nss                  = SPI_NSS_SOFT;//
#endif
    spi_init_struct.prescale             = SPI_PSC_2;//SPI_PSC_32;
    spi_init_struct.endian               = SPI_ENDIAN_MSB;
    spi_init(SPI1, &spi_init_struct);
    /* configure SPI0 byte access to FIFO */
    //spi_fifo_access_size_config(SPI1, SPI_BYTE_ACCESS);
    /* set crc polynomial */
    //spi_crc_polynomial_set(SPI0, 7);
    /* quad wire SPI_IO2 and SPI_IO3 pin output enable */
    //qspi_io23_output_enable(SPI0);
    /* enable SPI0 */
    spi_enable(SPI1);
}

void lcd_gpio_init()
{
    rcu_periph_clock_enable(RCU_GPIOA);
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_15);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15);
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_8);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_8);
    gpio_bit_set(GPIOA, GPIO_PIN_8);
    rcu_periph_clock_enable(RCU_GPIOC);
    BL_CTRL_OFF;
    spi_io_init(SPI_FRAMESIZE_8BIT);
}

void LCD_WriteRAM_Prepare()
//开始写GRAM
{
    //LCD_WR_REG(lcddev.wramcmd);
    spi_io_init(SPI_FRAMESIZE_16BIT);
    SPI_CS_0;
    SPI_DC_1;
}
void LCD_WriteRAM_Prepare_16()
//开始写GRAM
{
    //LCD_WR_REG(lcddev.wramcmd);
    spi_io_init(SPI_FRAMESIZE_16BIT);
    SPI_CS_0;
    SPI_DC_1;
}


void LCD_Init_bak(void)
{
    //gpio_bit_reset(RCU_GPIOD, GPIO_PIN_15);
    log_debug("\r\n === lcd_init ... === \r\n");
    gpio_bit_set(GPIOA, GPIO_PIN_15);
    vTaskDelay(1 / portTICK_RATE_MS);
    gpio_bit_reset(GPIOA, GPIO_PIN_15);
    vTaskDelay(10 / portTICK_RATE_MS);
    gpio_bit_set(GPIOA, GPIO_PIN_15);
    vTaskDelay(240 / portTICK_RATE_MS);
    LCD_WR_REG(0x11);     //Sleep out
    vTaskDelay(150 / portTICK_RATE_MS);
    LCD_WR_REG(0xB1);     //In normal mode
    LCD_WR_DATA(0x00);   //frame rate=85.3Hz
    LCD_WR_DATA(0x2C);
    LCD_WR_DATA(0x2B);
    LCD_WR_REG(0xB2);     //In Idle mode
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x01);
    LCD_WR_REG(0xB3);     //In partial mode
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x01);
    LCD_WR_REG(0xB4);     //DOT inversion Display Inversion Control
    LCD_WR_DATA(0x03);
    LCD_WR_REG(0xB9);     //In normal mode
    LCD_WR_DATA(0xFF);
    LCD_WR_DATA(0x83);
    LCD_WR_DATA(0x47);
    LCD_WR_REG(0xC0);     //VRH: Set the GVDD
    LCD_WR_DATA(0xA2);
    LCD_WR_DATA(0x02);
    LCD_WR_DATA(0x84);
    LCD_WR_REG(0xC1);     //set VGH/ VGL
    LCD_WR_DATA(0x02);   //??02 VGH=16.6 VGL=-7.5  00 VGH=11.6 VGL=-7.5  06 VGH=16.6  VGL=-10
    LCD_WR_REG(0xC2);     //APA: adjust the operational amplifier DCA: adjust the booster Voltage
    LCD_WR_DATA(0x9);
    //LCD_WR_DATA(0x00);
    LCD_WR_REG(0xC3);     //In Idle mode (8-colors)
    LCD_WR_DATA(0x8A);
    LCD_WR_DATA(0x2A);
    LCD_WR_REG(0xC4);     //In partial mode + Full color
    LCD_WR_DATA(0x8A);
    LCD_WR_DATA(0xEE);
    LCD_WR_REG(0xC5);     //VCOM
    LCD_WR_DATA(0x09);
    LCD_WR_REG(0x20);     //Display inversion
    LCD_WR_REG(0xC7);
    LCD_WR_DATA(0x10);
    LCD_WR_REG(0x36);     //MX, MY, RGB mode
    LCD_WR_DATA(0xC0); //08
    LCD_WR_REG(0xE0);
    LCD_WR_DATA(0x0C);
    LCD_WR_DATA(0x1C);
    LCD_WR_DATA(0x1B);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x2F);
    LCD_WR_DATA(0x28);
    LCD_WR_DATA(0x20);
    LCD_WR_DATA(0x24);
    LCD_WR_DATA(0x23);
    LCD_WR_DATA(0x22);
    LCD_WR_DATA(0x2A);
    LCD_WR_DATA(0x36);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x05);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x10);
    LCD_WR_REG(0xE1);
    LCD_WR_DATA(0x0C);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x2E);
    LCD_WR_DATA(0x27);
    LCD_WR_DATA(0x21);
    LCD_WR_DATA(0x24);
    LCD_WR_DATA(0x24);
    LCD_WR_DATA(0x22);
    LCD_WR_DATA(0x2A);
    LCD_WR_DATA(0x35);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x05);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x10);
    LCD_WR_REG(0x35);     //65k mode
    LCD_WR_DATA(0x00);
    LCD_WR_REG(0x3A);     //65k mode
    LCD_WR_DATA(0x05);
    LCD_WR_REG(0x29);     //Display on
}




//写寄存器
//LCD_Reg:寄存器编号
//LCD_RegValue:要写入的值
void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue)
{
    LCD_WR_REG(LCD_Reg);
    LCD_WriteRAM(LCD_RegValue);
}


//当mdk -O1时间优化时需要设置
//延时i
void opt_delay(uint8_t i)
{
    while(i--);
}

//LCD开启显示
void LCD_DisplayOn(void)
{
    LCD_WR_REG(0X29);   //开启显示
}
//LCD关闭显示
void LCD_DisplayOff(void)
{
    LCD_WR_REG(0X28);   //关闭显示
}
//设置光标位置
//Xpos:横坐标
//Ypos:纵坐标
void LCD_SetCursor(uint32_t Xpos, uint32_t Ypos)
{
#if 1
    //5us
    SPI_CS_0;
    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)lcddev.setxcmd;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_1;
    SPI_DATA(SPI1) = 0;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = Xpos;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)lcddev.setycmd;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_1;
    SPI_DATA(SPI1) = 0;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = Ypos;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)lcddev.wramcmd;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_CS_1;
#else
    //8us
    LCD_WR_REG(lcddev.setxcmd);
    LCD_WR_DATA(0);
    LCD_WR_DATA(Xpos & 0XFF);
    LCD_WR_REG(lcddev.setycmd);
    LCD_WR_DATA(0);
    LCD_WR_DATA(Ypos & 0XFF);
#endif
}
void LCD_SetCursor_bak(uint16_t Xpos, uint16_t Ypos)
{
    LCD_WR_REG(lcddev.setxcmd);
    LCD_WR_DATA(Xpos >> 8);
    LCD_WR_DATA(Xpos & 0XFF);
    LCD_WR_REG(lcddev.setycmd);
    LCD_WR_DATA(Ypos >> 8);
    LCD_WR_DATA(Ypos & 0XFF);
}
//画点
//x,y:坐标
//POINT_COLOR:此点的颜色
void LCD_DrawPoint(uint16_t x, uint16_t y)
{
    LCD_SetCursor(x, y);    //设置光标位置
    //LCD_WR_REG(lcddev.wramcmd);
    //LCD_WriteRAM_Prepare();   //开始写入GRAM
    LCD_WriteRAM_8(POINT_COLOR);
    //LCD_WriteRAM_End;
}
void LCD_DrawPoint_back(uint16_t x, uint16_t y)
{
    LCD_SetCursor(x, y);    //设置光标位置
    //LCD_WR_REG(lcddev.wramcmd);
    //LCD_WriteRAM_Prepare();   //开始写入GRAM
    LCD_WriteRAM_8(BACK_COLOR);
    //LCD_WriteRAM_End;
}

void LCD_DrawPoint2(uint16_t x, uint16_t y)
{
    LCD_SetCursor(x, y);    //设置光标位置
    //LCD_WR_REG(lcddev.wramcmd);
    //LCD_WriteRAM_Prepare();   //开始写入GRAM
    LCD_WriteRAM_8(POINT_COLOR);
    //LCD_WriteRAM_End;
}
//快速画点
//x,y:坐标
//color:颜色
void LCD_Fast_DrawPoint(uint16_t x, uint16_t y, uint16_t color)
{
    //设置光标位置
    LCD_SetCursor(x, y); //LCD_WR_REG(lcddev.wramcmd);
    //LCD_WriteRAM_Prepare();
    LCD_WriteRAM_8(color);
    //LCD_WriteRAM(color);
    //LCD_WriteRAM_End;
    //写入颜色
    //LCD_WriteReg(lcddev.wramcmd,color);
}


//dir:方向选择  0-0度旋转，1-180度旋转，2-270度旋转，3-90度旋转
void LCD_Display_Dir(uint8_t dir)
{
    if(dir == 0 || dir == 1) {  //竖屏
        lcddev.dir = 0; //竖屏
        lcddev.width = 128;
        lcddev.height = 160;
        lcddev.wramcmd = 0X2C;
        lcddev.setxcmd = 0X2A;
        lcddev.setycmd = 0X2B;

        if(dir == 0) {    //0-0度旋转
            LCD_WR_REG(0x36);
            LCD_WR_DATA((0 << 3) | (1 << 7) | (1 << 6) | (0 << 5));

        } else {                         //1-180度旋转
            LCD_WR_REG(0x36);
            LCD_WR_DATA((0 << 3) | (0 << 7) | (0 << 6) | (0 << 5));
        }

    } else if(dir == 2 || dir == 3) {
        lcddev.dir = 1; //横屏
        lcddev.width = 160;
        lcddev.height = 128;
        lcddev.wramcmd = 0X2C;
        lcddev.setxcmd = 0X2A;
        lcddev.setycmd = 0X2B;

        if(dir == 2) {          //2-270度旋转
            LCD_WR_REG(0x36);
            LCD_WR_DATA((0 << 3) | (0 << 7) | (1 << 6) | (1 << 5));

        } else {                         //3-90度旋转
            LCD_WR_REG(0x36);
            LCD_WR_DATA((0 << 3) | (1 << 7) | (0 << 6) | (1 << 5));
        }
    }

    //设置显示区域
    LCD_WR_REG(lcddev.setxcmd);
    LCD_WR_DATA(0);
    LCD_WR_DATA(0);
    LCD_WR_DATA((lcddev.width - 1) >> 8);
    LCD_WR_DATA((lcddev.width - 1) & 0XFF);
    LCD_WR_REG(lcddev.setycmd);
    LCD_WR_DATA(0);
    LCD_WR_DATA(0);
    LCD_WR_DATA((lcddev.height - 1) >> 8);
    LCD_WR_DATA((lcddev.height - 1) & 0XFF);
}
//设置窗口,并自动设置画点坐标到窗口左上角(sx,sy).
//sx,sy:窗口起始坐标(左上角)
//width,height:窗口宽度和高度,必须大于0!!
//窗体大小:width*height.
void LCD_Set_Window(uint16_t sx, uint16_t sy, uint16_t width, uint16_t height)
{
    uint16_t twidth, theight;
    twidth = sx + width - 1;
    theight = sy + height - 1;
    SPI_CS_0;
    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)lcddev.setxcmd;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_1;
    SPI_DATA(SPI1) = (uint32_t)sx >> 8;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = (uint32_t)sx & 0XFF;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = (uint32_t)twidth >> 8;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = (uint32_t)twidth & 0XFF;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)lcddev.setycmd;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_1;
    SPI_DATA(SPI1) = (uint32_t)sy >> 8;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = (uint32_t)sy & 0XFF;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = (uint32_t)theight >> 8;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DATA(SPI1) = (uint32_t)theight & 0XFF;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    SPI_DC_0;
    SPI_DATA(SPI1) = (uint32_t)lcddev.wramcmd;

    while(RESET == spi_i2s_flag_get(SPI1, SPI_TXLVL_EMPTY));

    //LCD_WR_REG(lcddev.wramcmd);
    SPI_CS_1;
}





//清屏函数
//color:要清屏的填充色
void LCD_Clear(uint16_t color)
{
    uint32_t index = 0;
    uint32_t totalpoint = lcddev.width;
    totalpoint *= lcddev.height;        //得到总点数
    //0us
    //vTaskDelay(1 / portTICK_RATE_MS);
    LCD_SetCursor(0x00, 0x0000); //设置光标位置
    //LCD_WR_REG(lcddev.wramcmd);
    LCD_WriteRAM_Prepare();             //开始写入GRAM
    //30us
    //vTaskDelay(1 / portTICK_RATE_MS);
#ifdef SPI_USE_DMA
    //TEST_HIGH;//40ms

    for(index = 0; index < lcddev.height; index++) {
        LCD_RAM_DMA_W_color(&color, lcddev.width);
    }

#else

    for(index = 0; index < lcddev.height; index++) {
        //if((index % 0x8) == 0) {
        //TEST_LOW;
        //vTaskDelay(1 / portTICK_RATE_MS);
        //TEST_HIGH;
        //}
        uint32_t a ;

        for(a = 0; a < lcddev.width; a++) {
            LCD_WriteRAM(color);
            //
        }
    }

#endif
    LCD_WriteRAM_End;
}
//在指定区域内填充指定颜色
//区域大小:(xend-xsta+1)*(yend-ysta+1)
//xsta
//color:要填充的颜色
void LCD_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color)
{
    uint16_t i, j;
    uint16_t xlen = 0;
    uint16_t temp;

    if((lcddev.id == 0X6804) && (lcddev.dir == 1)) { //6804横屏的时候特殊处理
        temp = sx;
        sx = sy;
        sy = lcddev.width - ex - 1;
        ex = ey;
        ey = lcddev.width - temp - 1;
        lcddev.dir = 0;
        lcddev.setxcmd = 0X2A;
        lcddev.setycmd = 0X2B;
        LCD_Fill(sx, sy, ex, ey, color);
        lcddev.dir = 1;
        lcddev.setxcmd = 0X2B;
        lcddev.setycmd = 0X2A;

    } else {
        xlen = ex - sx + 1;
#if 1
        //vTaskDelay(1 / portTICK_RATE_MS);
        //TEST_HIGH;
        LCD_Set_Window(sx, sy, ex - sx, ey - sy);
        //LCD_WR_REG(lcddev.wramcmd);
        LCD_WriteRAM_Prepare();
        //34us

        for(i = sy; i <= ey; i++) {
            //if((i % 8) == 0) {
            //TEST_LOW;
            //vTaskDelay(1 / portTICK_RATE_MS);
            //TEST_HIGH;
            //}
#ifdef SPI_USE_DMA
            LCD_RAM_DMA_W_color(&color, xlen);
#else

            for(j = 0; j < xlen; j++) {
                LCD_WriteRAM(color);    //设置光标位置 150us
            }

#endif
        }

        //TEST_LOW;
        //vTaskDelay(1 / portTICK_RATE_MS);
        LCD_WriteRAM_End;
#else

        for(i = sy; i <= ey; i++) {
            LCD_SetCursor(sx, i);                   //设置光标位置
            //LCD_WR_REG(lcddev.wramcmd);
            LCD_WriteRAM_Prepare();                 //开始写入GRAM

            for(j = 0; j < xlen; j++) {
                LCD_WriteRAM(color);    //设置光标位置
            }

            LCD_WriteRAM_End;
        }

#endif
        LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复显示窗口为全屏
    }
}
//在指定区域内填充指定颜色块
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
//color:要填充的颜色
void LCD_Color_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t* color)
{
    uint16_t height, width;
    uint16_t i, j;
    width = ex - sx + 1;    //得到填充的宽度
    height = ey - sy + 1;   //高度

    for(i = 0; i < height; i++) {
        LCD_SetCursor(sx, sy + i);  //设置光标位置
        //LCD_WR_REG(lcddev.wramcmd);
        LCD_WriteRAM_Prepare();     //开始写入GRAM

        for(j = 0; j < width; j++) {
            LCD_WriteRAM(color[i * width + j]);    //写入数据
        }

        LCD_WriteRAM_End;
    }
}
//画线
//x1,y1:起点坐标
//x2,y2:终点坐标
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
    uint16_t t;
    int xerr = 0, yerr = 0, delta_x, delta_y, distance;
    int incx, incy, uRow, uCol;
    delta_x = x2 - x1; //计算坐标增量
    delta_y = y2 - y1;
    uRow = x1;
    uCol = y1;

    if(delta_x > 0) {
        incx = 1;    //设置单步方向

    } else if(delta_x == 0) {
        incx = 0;    //垂直线

    } else {
        incx = -1;
        delta_x = -delta_x;
    }

    if(delta_y > 0) {
        incy = 1;

    } else if(delta_y == 0) {
        incy = 0;    //水平线

    } else {
        incy = -1;
        delta_y = -delta_y;
    }

    if(delta_x > delta_y) {
        distance = delta_x;    //选取基本增量坐标轴

    } else {
        distance = delta_y;
    }

#if 1
    //LCD_Set_Window(x1, y1, x2, y2);
    LCD_Set_Window(x1, y1, delta_x + 1, delta_y + 1);
    //LCD_WR_REG(lcddev.wramcmd);
    //LCD_WriteRAM_Prepare();

    for(t = 0; t <= distance ; t++) { //画线输出
        //LCD_DrawPoint2(uRow,uCol);//画点
        LCD_WriteRAM_8(POINT_COLOR);
        xerr += delta_x ;
        yerr += delta_y ;

        if(xerr > distance) {
            xerr -= distance;
            uRow += incx;
        }

        if(yerr > distance) {
            yerr -= distance;
            uCol += incy;
        }
    }

    //LCD_WriteRAM_End;
    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复显示窗口为全屏
#else

    for(t = 0; t <= distance + 1; t++) { //画线输出
        LCD_DrawPoint(uRow, uCol); //画点
        xerr += delta_x ;
        yerr += delta_y ;

        if(xerr > distance) {
            xerr -= distance;
            uRow += incx;
        }

        if(yerr > distance) {
            yerr -= distance;
            uCol += incy;
        }
    }

#endif
}
//画矩形
//(x1,y1),(x2,y2):矩形的对角坐标
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
    LCD_DrawLine(x1, y1, x2, y1);
    LCD_DrawLine(x1, y1, x1, y2);
    LCD_DrawLine(x1, y2, x2, y2);
    LCD_DrawLine(x2, y1, x2, y2);
}
//在指定位置画一个指定大小的圆
//(x,y):中心点
//r    :半径
void LCD_Draw_Circle(uint16_t x0, uint16_t y0, uint8_t r)
{
    int a, b;
    int di;
    a = 0;
    b = r;
    di = 3 - (r << 1);       //判断下个点位置的标志

    while(a <= b) {
        LCD_DrawPoint(x0 + a, y0 - b);        //5
        LCD_DrawPoint(x0 + b, y0 - a);        //0
        LCD_DrawPoint(x0 + b, y0 + a);        //4
        LCD_DrawPoint(x0 + a, y0 + b);        //6
        LCD_DrawPoint(x0 - a, y0 + b);        //1
        LCD_DrawPoint(x0 - b, y0 + a);
        LCD_DrawPoint(x0 - a, y0 - b);        //2
        LCD_DrawPoint(x0 - b, y0 - a);        //7
        a++;

        //使用Bresenham算法画圆
        if(di < 0) {
            di += 4 * a + 6;

        } else {
            di += 10 + 4 * (a - b);
            b--;
        }
    }
}
//在指定位置显示一个字符
//x,y:起始坐标
//num:要显示的字符:" "--->"~"
//size:字体大小 12/16/24
//mode:叠加方式(1)还是非叠加方式(0)
void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode)
{
    uint8_t temp, t1, t;
    uint16_t y0 = y;
    uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); //得到字体一个字符对应点阵集所占的字节数
    num = num - ' '; //得到偏移后的值（ASCII字库是从空格开始取模，所以-' '就是对应字符的字库）

    //log_debug("csize=%d\n",csize);

    for(t = 0; t < csize; t++) {
        if((t & 0x7) == 0) {
            //vTaskDelay(1 / portTICK_RATE_MS);
        }

        if(size == 12) {
            temp = asc2_1206[num][t];    //调用1206字体

        } else if(size == 16) {
            temp = asc2_1608[num][t];    //调用1608字体

        } else if(size == 24) {
            temp = asc2_2412[num][t];    //调用2412字体

        } else {
            return;    //没有的字库
        }

        for(t1 = 0; t1 < 8; t1++) {
            if(temp & 0x80) {
                LCD_Fast_DrawPoint(x, y, POINT_COLOR);

            } else if(mode == 0) {
                LCD_Fast_DrawPoint(x, y, BACK_COLOR);
            }

            temp <<= 1;
            y++;

            if(y >= lcddev.height) {
                return;     //超区域了
            }

            if((y - y0) == size) {
                y = y0;
                x++;

                if(x >= lcddev.width) {
                    return; //超区域了
                }

                break;
            }
        }
    }
}
//m^n函数
//返回值:m^n次方.
uint32_t LCD_Pow(uint8_t m, uint8_t n)
{
    uint32_t result = 1;

    while(n--) {
        result *= m;
    }

    return result;
}
//显示数字,高位为0,则不显示
//x,y :起点坐标
//len :数字的位数
//size:字体大小
//color:颜色
//num:数值(0~4294967295);
void LCD_ShowNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size)
{
    uint8_t t, temp;
    uint8_t enshow = 0;

    for(t = 0; t < len; t++) {
        temp = (num / LCD_Pow(10, len - t - 1)) % 10;

        if(enshow == 0 && t < (len - 1)) {
            if(temp == 0) {
                LCD_ShowChar(x + (size / 2)*t, y, '0', size, 0);
                continue;

            } else {
                enshow = 1;
            }
        }

        LCD_ShowChar(x + (size / 2)*t, y, temp + '0', size, 0);
    }
}
//显示数字,高位为0,还是显示
//x,y:起点坐标
//num:数值(0~999999999);
//len:长度(即要显示的位数)
//size:字体大小
//mode:
//[7]:0,不填充;1,填充0.
//[6:1]:保留
//[0]:0,非叠加显示;1,叠加显示.
void LCD_ShowxNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t mode)
{
    uint8_t t, temp;
    uint8_t enshow = 0;

    for(t = 0; t < len; t++) {
        temp = (num / LCD_Pow(10, len - t - 1)) % 10;

        if(enshow == 0 && t < (len - 1)) {
            if(temp == 0) {
                if(mode & 0X80) {
                    LCD_ShowChar(x + (size / 2)*t, y, '0', size, mode & 0X01);

                } else {
                    LCD_ShowChar(x + (size / 2)*t, y, ' ', size, mode & 0X01);
                }

                continue;

            } else {
                enshow = 1;
            }
        }

        LCD_ShowChar(x + (size / 2)*t, y, temp + '0', size, mode & 0X01);
    }
}
//显示字符串
//x,y:起点坐标
//width,height:区域大小
//size:字体大小
//*p:字符串起始地址
void LCD_ShowString(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t size, char* p)
{
    uint8_t x0 = x;
    width += x;
    height += y;

    while((*p <= '~') && (*p >= ' ')) { //判断是不是非法字符!
        if(x >= width) {
            x = x0;
            y += size;
        }

        if(y >= height) {
            break;    //退出
        }

        LCD_ShowChar(x, y, *p, size, 0);
        x += size / 2;
        p++;
    }
}


//汉字 32*32
void GUI_DrawFont32(uint16_t x, uint16_t y, char* s, uint8_t mode)
{
    uint8_t i, j;
    uint16_t k;
    uint16_t HZnum;
    uint16_t x0 = x;
    HZnum = sizeof(tfont32) / sizeof(typFNT_GB32); //自动统计汉字数目

    for(k = 0; k < HZnum; k++) {
        if((tfont32[k].Index[0] == *(s)) && (tfont32[k].Index[1] == *(s + 1))) {
            LCD_Set_Window(x, y, 32, 32);
            //LCD_WR_REG(lcddev.wramcmd);
            LCD_WriteRAM_Prepare();

            for(i = 0; i < 32 * 4; i++) {
                for(j = 0; j < 8; j++) {
                    if(!mode) { //非叠加方式
                        if(tfont32[k].Msk[i] & (0x80 >> j)) {
                            LCD_WriteRAM(POINT_COLOR);

                        } else {
                            LCD_WriteRAM(BACK_COLOR);
                        }

                    } else {
                        //POINT_COLOR=fc;
                        if(tfont32[k].Msk[i] & (0x80 >> j)) {
                            LCD_DrawPoint(x, y);    //画一个点
                        }

                        x++;

                        if((x - x0) == 32) {
                            x = x0;
                            y++;
                            break;
                        }
                    }
                }
            }

            LCD_WriteRAM_End;
        }

        continue;  //查找到对应点阵字库立即退出，防止多个汉字重复取模带来影响
    }

    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复窗口为全屏
}

//spain
void GUI_DrawFont8(uint16_t x, uint16_t y, char* s, uint8_t mode)
{
    uint8_t i, j;
    uint16_t k;
    uint16_t HZnum;
    uint16_t x0 = x;
    HZnum = sizeof(tfont8) / sizeof(typFNT_sp8); //自动统计汉字数目
    //vTaskDelay(1 / portTICK_RATE_MS);

    //log_debug("HZnum=%d\n",HZnum);//4
    for(k = 0; k < HZnum; k++) {
        //log_debug("k=%d\n",k);
        //log_debug("(%d) %x%x\n",k,tfont8[k].Index[0],tfont8[k].Index[1]);
        //log_debug("      %x%x\n",*s,*(s+1));
        if((tfont8[k].Index[0] == *(s)) && (tfont8[k].Index[1] == *(s + 1))) {
            LCD_Set_Window(x, y, 8, 16);

            //LCD_WR_REG(lcddev.wramcmd);
            //LCD_WriteRAM_Prepare();

            for(i = 0; i < 16 ; i++) {
                //if((i & 0x7) == 6) {
                //vTaskDelay(1 / portTICK_RATE_MS);
                //}

                //vTaskDelay(1/portTICK_RATE_MS );
                for(j = 0; j < 8; j++) {
                    if(!mode) { //非叠加方式
                        if(tfont8[k].Msk[i] & (0x80 >> j)) {
                            LCD_WriteRAM_8(POINT_COLOR);

                        } else {
                            LCD_WriteRAM_8(BACK_COLOR);
                        }

                    } else {
                        //POINT_COLOR=fc;
                        if(tfont8[k].Msk[i] & (0x80 >> j)) {
                            LCD_DrawPoint2(x, y);    //画一个点
                        }

                        x++;

                        if((x - x0) == 8) {
                            x = x0;
                            y++;
                            break;
                        }
                    }
                }
            }

            //LCD_WriteRAM_End;
        }

        continue;  //查找到对应点阵字库立即退出，防止多个汉字重复取模带来影响
    }

    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复窗口为全屏
}

//汉字 16*16
void GUI_DrawFont16(uint16_t x, uint16_t y, char* s, uint8_t mode)
{
    uint8_t i, j;
    uint16_t k;
    uint16_t HZnum;
    uint16_t x0 = x;
    HZnum = sizeof(tfont16) / sizeof(typFNT_GB16); //自动统计汉字数目
    //vTaskDelay(1 / portTICK_RATE_MS);

    //log_debug("HZnum=%d\n",HZnum);//4
    for(k = 0; k < HZnum; k++) {
        //log_debug("k=%d\n",k);
        //log_debug("(%d) %x%x%x\n",k,tfont16[k].Index[0],tfont16[k].Index[1],tfont16[k].Index[2]);
        //log_debug("      %x%x\n",*s,*(s+1));
        if((tfont16[k].Index[0] == *(s)) && (tfont16[k].Index[1] == *(s + 1)) && (tfont16[k].Index[2] == *(s + 2))) {
            LCD_Set_Window(x, y, 16, 16);

            //LCD_WR_REG(lcddev.wramcmd);
            //LCD_WriteRAM_Prepare();

            for(i = 0; i < 16 * 2; i++) {
                //if((i & 0x7) == 6) {
                //vTaskDelay(1 / portTICK_RATE_MS);
                //}

                //vTaskDelay(1/portTICK_RATE_MS );
                for(j = 0; j < 8; j++) {
                    if(!mode) { //非叠加方式
                        if(tfont16[k].Msk[i] & (0x80 >> j)) {
                            LCD_WriteRAM_8(POINT_COLOR);

                        } else {
                            LCD_WriteRAM_8(BACK_COLOR);
                        }

                    } else {
                        //POINT_COLOR=fc;
                        if(tfont16[k].Msk[i] & (0x80 >> j)) {
                            LCD_DrawPoint2(x, y);    //画一个点
                        }

                        x++;

                        if((x - x0) == 16) {
                            x = x0;
                            y++;
                            break;
                        }
                    }
                }
            }

            //LCD_WriteRAM_End;
        }

        continue;  //查找到对应点阵字库立即退出，防止多个汉字重复取模带来影响
    }

    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复窗口为全屏
}

//汉字 24*24
void GUI_DrawFont24(uint16_t x, uint16_t y, char* s, uint8_t mode)
{
    uint8_t i, j;
    uint16_t k;
    uint16_t HZnum;
    uint16_t x0 = x;
    HZnum = sizeof(tfont24) / sizeof(typFNT_GB24); //自动统计汉字数目

    for(k = 0; k < HZnum; k++) {
        if((tfont24[k].Index[0] == *(s)) && (tfont24[k].Index[1] == *(s + 1))) {
            LCD_Set_Window(x, y, 24, 24);
            //LCD_WR_REG(lcddev.wramcmd);
            LCD_WriteRAM_Prepare();

            for(i = 0; i < 24 * 3; i++) {
                for(j = 0; j < 8; j++) {
                    if(!mode) { //非叠加方式
                        if(tfont24[k].Msk[i] & (0x80 >> j)) {
                            LCD_WriteRAM(POINT_COLOR);

                        } else {
                            LCD_WriteRAM(BACK_COLOR);
                        }

                    } else {
                        //POINT_COLOR=fc;
                        if(tfont24[k].Msk[i] & (0x80 >> j)) {
                            LCD_DrawPoint2(x, y);    //画一个点
                        }

                        x++;

                        if((x - x0) == 24) {
                            x = x0;
                            y++;
                            break;
                        }
                    }
                }
            }

            LCD_WriteRAM_End;
        }

        continue;  //查找到对应点阵字库立即退出，防止多个汉字重复取模带来影响
    }

    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复窗口为全屏
}


//显示40*40图片
void Gui_Drawbmp16(uint16_t x, uint16_t y, const unsigned char* p) //显示40*40图片
{
    int i;
    unsigned char picH, picL;
    LCD_Set_Window(x, y, 40, 40);
    //LCD_WR_REG(lcddev.wramcmd);
    LCD_WriteRAM_Prepare();

    for(i = 0; i < 40 * 40; i++) {
        picL = *(p + i * 2); //数据低位在前
        picH = *(p + i * 2 + 1);
        LCD_WriteRAM(((picH << 8) | picL));
    }

    LCD_WriteRAM_End;
    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复显示窗口为全屏
}
void Gui_Drawbmp16_2(XY_SIZE_T* xy, const unsigned char* p)  //显示40*40图片
{
    uint16_t i, j;
    unsigned char picH, picL;
    uint16_t pic;
    LCD_Set_Window(xy->x, xy->y, xy->w, xy->h);
    //LCD_WR_REG(lcddev.wramcmd);
    LCD_WriteRAM_Prepare();
    //vTaskDelay(2 / portTICK_RATE_MS);

    for(j = 0; j < (xy->h * 2); j += 2) {
        //if((j % 16) == 12) {
        //vTaskDelay(1 / portTICK_RATE_MS);
        //}
#ifdef SPI_USE_DMA
        //if(j==18){
        LCD_RAM_DMA_W_addr((uint16_t*)(p + j * xy->w), xy->w);
        //pic=WHITE;
        //LCD_RAM_DMA_W_color(&pic, 8);
        //pic=RED;
        //LCD_WriteRAM(pic);
        //LCD_RAM_DMA_W_color(&pic, 6);
        //break;
        //}else if(j==12){
        //LCD_RAM_DMA_W_addr_32((uint16_t *)(p + j * xy->w), xy->w);
        //break;
#else

        for(i = 0; i < (xy->w * 2); i += 2) {
            //picL = *(p + i * 2 + j*xy->w*2); //数据低位在前
            //picH = *(p + i * 2 + 1+j*xy->w*2);
            //LCD_WriteRAM(((picH << 8) | picL));
            pic = *(uint16_t*)(p + i + j * xy->w);
            LCD_WriteRAM(pic);
        }

#endif
    }

    LCD_WriteRAM_End;
    LCD_Set_Window(0, 0, lcddev.width, lcddev.height); //恢复显示窗口为全屏
}


//显示汉字或者字符串
void Show_Str(uint16_t x, uint16_t y, char* str, uint8_t size, uint8_t mode)
{
    uint16_t x0 = x;
    uint8_t bHz = 0, i;  //字符或者中文
    char* p = str;

    while(*str != 0) { //数据未结束
        //if((index&0x7)==0){

        //}
        if(!bHz) {
            if(x > (lcddev.width - size / 2) || y > (lcddev.height - size)) {
                return;
            }

            if(*str > 0x80) {
                bHz = 1;    //中文

            } else {          //字符
                if(*str == 0x0D) { //换行符号
                    y += size;
                    x = x0;
                    str++;

                } else {
                    /* if(size >= 24) { //字库中没有集成12X24 16X32的英文字体,用8X16代替
                         LCD_ShowChar(x, y, *str, 24, mode);
                         x += 12; //字符,为全字的一半

                     } else {*/
                    LCD_ShowChar(x, y, *str, size, mode);
                    x += size / 2; //字符,为全字的一半
                    //}
                }

                str++;
            }

        } else { //中文
            if(x > (lcddev.width - size) || y > (lcddev.height - size)) {
                return;
            }

            bHz = 0; //有汉字库
            /*if(size == 32) {
                GUI_DrawFont32(x, y, str, mode);

            } else if(size == 24) {
                GUI_DrawFont24(x, y, str, mode);

            } else */{
                GUI_DrawFont16(x, y, str, mode);
            }
            str += 3;
            x += size; //下一个汉字偏移
        }
    }
}


void Show_spain_Str(uint16_t x, uint16_t y, char* str, uint8_t size, uint8_t mode)
{
    uint16_t x0 = x;
    uint8_t bHz = 0, i;  //字符或者中文
    char* p = str;

    while(*str != 0) { //数据未结束
        //if((index&0x7)==0){

        //}
        if(!bHz) {
            if(x > (lcddev.width - size / 2) || y > (lcddev.height - size)) {
                return;
            }

            if(*str > 0x80) {
                bHz = 1;    //中文

            } else {          //字符
                if(*str == 0x0D) { //换行符号
                    y += size;
                    x = x0;
                    str++;

                } else {
                    /* if(size >= 24) { //字库中没有集成12X24 16X32的英文字体,用8X16代替
                         LCD_ShowChar(x, y, *str, 24, mode);
                         x += 12; //字符,为全字的一半

                     } else {*/
                    //LCD_ShowChar(x, y, *str, size, mode);
                    x += size / 2; //字符,为全字的一半
                    //}
                }

                str++;
            }

        } else { //中文
            if(x > (lcddev.width - size) || y > (lcddev.height - size)) {
                return;
            }

            bHz = 0; //有汉字库
            /*if(size == 32) {
                GUI_DrawFont32(x, y, str, mode);

            } else if(size == 24) {
                GUI_DrawFont24(x, y, str, mode);

            } else */{
                GUI_DrawFont8(x, y, str, mode);
            }
            str += 2;
            x += size; //下一个汉字偏移
        }
    }
}



//居中显示


void Gui_StrCenter(uint16_t x, uint16_t y, char* str, uint8_t size, uint8_t mode)
{
    uint16_t x1;
    unsigned int len = (unsigned int)strlen((const char*)str);

    if(size > 16) {
        x1 = (lcddev.width - len * (size / 2)) / 2;

    } else {
        x1 = (lcddev.width - len * 16 / 3) / 2;
    }

    //uint32_t start = xTaskGetTickCount();
    Show_Str(x + x1, y, str, size, mode);
    //uint32_t end = xTaskGetTickCount();
    //log_debug("Show_Str diff %d\n",end-start);
}



//主固定栏
void DrawTestPage(char* str)
{
    //绘制固定栏up
    LCD_Clear(BLACK);
    //uint32_t start = xTaskGetTickCount();
    LCD_Fill(0, 0, lcddev.width, 20, BLUE); //4MS
    //uint32_t end = xTaskGetTickCount();
    //log_debug("LCD_Fill diff %d\n",end-start);
    //uint32_t start = xTaskGetTickCount();
#if 1
    POINT_COLOR = GREEN;
    LCD_DrawLine(0, 20, lcddev.width, 20); //7MS 5.3MS/3 1760US
    //uint32_t end = xTaskGetTickCount();
    //log_debug("LCD_DrawLine diff %d\n",end-start);
    POINT_COLOR = BLUE;
    LCD_DrawLine(0, 21, lcddev.width, 21);
    POINT_COLOR = BRRED;
    LCD_DrawLine(0, 22, lcddev.width, 22);
#endif
    //绘制固定栏down
    LCD_Fill(0, lcddev.height - 20, lcddev.width, lcddev.height, BLUE);
#if 1
    POINT_COLOR = GREEN;
    LCD_DrawLine(0, lcddev.height - 20, lcddev.width, lcddev.height - 20);
    POINT_COLOR = BLUE;
    LCD_DrawLine(0, lcddev.height - 21, lcddev.width, lcddev.height - 21);
    POINT_COLOR = BRRED;
    LCD_DrawLine(0, lcddev.height - 22, lcddev.width, lcddev.height - 22);
#endif
    POINT_COLOR = LIGHTBLUE;
    Gui_StrCenter(0, 2, str, 16, 1); //居中显示
    //Show_Str(0, 83, "", 16, 1);
    //Gui_StrCenter(0, lcddev.height - 48, "中力电子", 16, 1); //居中显示
}

void DrawPage(char* str, uint16_t color)
{
    //绘制固定栏up
    LCD_Clear(color);
    //uint32_t start = xTaskGetTickCount();
    //TEST_HIGH;
    //LCD_Fill(0, 0, lcddev.width, 23, BLUE); //4MS
    //TEST_LOW;
    //return;
    //uint32_t end = xTaskGetTickCount();
    //log_debug("LCD_Fill diff %d\n",end-start);
    //uint32_t start = xTaskGetTickCount();
#if 1
    POINT_COLOR = GREEN;
    //LCD_DrawLine(0, 20, lcddev.width, 20); //7MS 5.3MS/3 1760US
    //uint32_t end = xTaskGetTickCount();
    //log_debug("LCD_DrawLine diff %d\n",end-start);
    POINT_COLOR = RED;
    //LCD_DrawLine(0, 21, lcddev.width, 21);
    //POINT_COLOR = BLACK;
    //LCD_DrawLine(0, 22, lcddev.width, 22);
#endif
    //绘制固定栏down
    //LCD_Fill(0, lcddev.height - 20, lcddev.width, lcddev.height, BLUE);
#if 1
    POINT_COLOR = GREEN;
    //LCD_DrawLine(0, lcddev.height - 20, lcddev.width, lcddev.height - 20);
    POINT_COLOR = BLUE;
    //LCD_DrawLine(0, lcddev.height - 21, lcddev.width, lcddev.height - 21);
    POINT_COLOR = BRRED;
    //LCD_DrawLine(0, lcddev.height - 22, lcddev.width, lcddev.height - 22);
#endif
    POINT_COLOR = ~color;
    Gui_StrCenter(0, 2, str, 16, 1); //居中显示
    POINT_COLOR = RED;
    //Show_Str(0, 83, "", 16, 1);
    //Gui_StrCenter(0, lcddev.height - 48, "中力电子", 16, 1); //居中显示
}

//中文测试
void Chinese_Font_test(void)
{
    DrawTestPage("温馨提示");
    POINT_COLOR = RED;  //画笔颜色
    BACK_COLOR = BLACK; //背景色
    /*Show_Str(10,30,"16X16:永达创力",16,1);
    Show_Str(10,50,"16X16:   显",16,1);
    Show_Str(10,70,"24X24:示",24,1);
    Show_Str(10,100,"32X32:屏",32,1);*/
    vTaskDelay(1000 / portTICK_RATE_MS);
}

//测试主页
/*void main_test(char* id)
{
    DrawTestPage("显示屏测诿);
    POINT_COLOR = RED;
    Gui_StrCenter(0, 30, "显示屿, 16, 1);
    POINT_COLOR = GREEN;
    Gui_StrCenter(0, 50, "测试程序", 16, 1);
    POINT_COLOR = BLUE;
    Gui_StrCenter(0, 70, id, 16, 1);
    POINT_COLOR = BLACK;
    Gui_StrCenter(0, 90, "128RGB*160", 16, 1);
    POINT_COLOR = BLACK;
    Gui_StrCenter(0, 110, "TEL:13528886365", 16, 1);
    vTaskDelay(1800 / portTICK_RATE_MS);
}*/
////////////////////////////////////////////////////////////////////////////////
//电容触摸屏专有部分
//画水平线
//x0,y0:坐标
//len:线长度
//color:颜色
void gui_draw_hline(uint16_t x0, uint16_t y0, uint16_t len, uint16_t color)
{
    if(len == 0) {
        return;
    }

    LCD_Fill(x0, y0, x0 + len - 1, y0, color);
}
//画实心圆
//x0,y0:坐标
//r:半径
//color:颜色
void gui_fill_circle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color)
{
    uint32_t i;
    uint32_t imax = ((uint32_t)r * 707) / 1000 + 1;
    uint32_t sqmax = (uint32_t)r * (uint32_t)r + (uint32_t)r / 2;
    uint32_t x = r;
    gui_draw_hline(x0 - r, y0, 2 * r, color);

    for(i = 1; i <= imax; i++) {
        if((i * i + x * x) > sqmax) { // draw lines from outside
            if(x > imax) {
                gui_draw_hline(x0 - i + 1, y0 + x, 2 * (i - 1), color);
                gui_draw_hline(x0 - i + 1, y0 - x, 2 * (i - 1), color);
            }

            x--;
        }

        // draw lines from inside (center)
        gui_draw_hline(x0 - x, y0 + i, 2 * x, color);
        gui_draw_hline(x0 - x, y0 - i, 2 * x, color);
    }
}
//图形测试
void FillRec_Test(void)
{
    uint8_t i = 0;
    DrawTestPage("图形显示");
    LCD_Fill(0, 24, lcddev.width, lcddev.height - 24, WHITE);

    for(i = 0; i < 5; i++) {
        POINT_COLOR = ColorTab[i];
        LCD_DrawRectangle(lcddev.width / 2 - 40 + (i * 15), lcddev.height / 2 - 5 + (i * 8), lcddev.width / 2 - 40 + (i * 15) + 20, lcddev.height / 2 - 5 + (i * 8) + 20);
        vTaskDelay(100 / portTICK_RATE_MS);
    }

    for(i = 0; i < 5; i++) {
        POINT_COLOR = ColorTab[i];
        LCD_Draw_Circle(30 + (i * 15), 50, 15);
        vTaskDelay(100 / portTICK_RATE_MS);
    }

    vTaskDelay(1500 / portTICK_RATE_MS);

    for(i = 0; i < 5; i++) {
        POINT_COLOR = ColorTab[i];
        LCD_Fill(lcddev.width / 2 - 40 + (i * 15), lcddev.height / 2 - 5 + (i * 8), lcddev.width / 2 - 40 + (i * 15) + 20, lcddev.height / 2 - 5 + (i * 8) + 20, POINT_COLOR);
        vTaskDelay(100 / portTICK_RATE_MS);
    }

    return;

    for(i = 0; i < 5; i++) {
        POINT_COLOR = ColorTab[i];
        gui_fill_circle(30 + (i * 15), 50, 15, POINT_COLOR);
        vTaskDelay(100 / portTICK_RATE_MS);
    }

    vTaskDelay(1500 / portTICK_RATE_MS);
}

//英文测试
void English_Font_test(void)
{
    DrawTestPage("英文显示");
    POINT_COLOR = RED;
    BACK_COLOR = WHITE;
    LCD_ShowString(10, 30, 200, 12, 12, "6X12:abc");
    LCD_ShowString(10, 45, 200, 12, 12, "6X12:ABC");
    POINT_COLOR = GREEN;
    LCD_ShowString(10, 60, 200, 16, 16, "8X16:abc");
    LCD_ShowString(10, 80, 200, 16, 16, "8X16:ABC");
    POINT_COLOR = BLUE;
    LCD_ShowString(10, 100, 200, 24, 24, "12X24:abc");
    //LCD_ShowString(10,128,200,24,24,"12X24:ABC");
    vTaskDelay(1500 / portTICK_RATE_MS);
}

//图片测试
void Pic_test(void)
{
    DrawTestPage("图片显示");
    //POINT_COLOR=BLUE;
    vTaskDelay(1500 / portTICK_RATE_MS);
    //LCD_Fill(0,20,lcddev.width,lcddev.height-20,WHITE);
#if 0
    Gui_Drawbmp16(42, 60, gImage_l);
#else
#if 0
    XY_SIZE_T xy;
    xy.x = 10;
    xy.y = 30;
    //xy.w = 40;
    //xy.h = 40;
    xy.w = 94;
    xy.h = 71;
    Gui_Drawbmp16_2(&xy, gImage_left);
#else
    XY_SIZE_T xy;
    xy.x = 0;
    xy.y = 0;
    //xy.w = 40;
    //xy.h = 40;
    xy.w = 128;
    xy.h = 160;
    //Gui_Drawbmp16_2(&xy, gImage_l);
    //Gui_Drawbmp16_2(&xy, gImage_setting);
#endif
    //
#endif
    vTaskDelay(1800 / portTICK_RATE_MS);
}

//旋转测试
void Rotate_Test(void)
{
    uint8_t num = 0;
    char* Direction[4] = {"Rotation:0", "Rotation:180", "Rotation:270", "Rotation:90"};

    for(num = 0; num < 4; num++) {
        LCD_Display_Dir(num);
        DrawTestPage("旋转测试");
        POINT_COLOR = BLUE;
        Show_Str(25, 30, Direction[num], 16, 1);
        Gui_Drawbmp16(40, 60, gImage_l);
        //vTaskDelay(1000/portTICK_RATE_MS );
    }

    LCD_Display_Dir(USE_LCM_DIR);
}



//彩条显色
void DispBand(void)
{
    unsigned int i, j, k;
    //unsigned int color[8]={RED,RED,GREEN,GREEN,BLUE,BLUE,WHITE,WHITE};
    unsigned int color[8] = {BLUE, GREEN, RED, GBLUE, BRED, YELLOW, BLACK, WHITE};
    LCD_Set_Window(0, 0, lcddev.width, lcddev.height);
    LCD_WriteRAM_Prepare();             //开始写入GRAM

    for(i = 0; i < 8; i++) {
        //vTaskDelay(1 / portTICK_RATE_MS);
        for(j = 0; j < lcddev.height / 8; j++) {
            if(j == 10) {
                //vTaskDelay(1 / portTICK_RATE_MS);
            }

            for(k = 0; k < lcddev.width; k++) {
                LCD_WriteRAM(color[i]);
            }
        }
    }

    for(j = 0; j < lcddev.height % 8; j++) {
        for(k = 0; k < lcddev.width; k++) {
            LCD_WriteRAM(color[7]);
        }
    }

    LCD_WriteRAM_End;
    vTaskDelay(1000 / portTICK_RATE_MS);
}

//纯色测试
void Color_Test(void)
{
    DispBand();
    LCD_Clear(WHITE);
    vTaskDelay(1000 / portTICK_RATE_MS);
    POINT_COLOR = BLACK;
    Show_Str(15, 15, "WHITE", 16, 1);
    vTaskDelay(1000 / portTICK_RATE_MS);
    POINT_COLOR = WHITE;
    LCD_Clear(RED);
    Show_Str(15, 15, "RED ", 16, 1);
    vTaskDelay(1000 / portTICK_RATE_MS);
    LCD_Clear(GREEN);
    Show_Str(15, 15, "GREEN ", 16, 1);
    vTaskDelay(1000 / portTICK_RATE_MS);
    LCD_Clear(BLUE);
    Show_Str(15, 15, "BLUE ", 16, 1);
    vTaskDelay(1000 / portTICK_RATE_MS);
}

//显示开关测试
void Switch_test(void)
{
    uint8_t num = 3;

    while(num--) {
        LCD_DisplayOff();
        vTaskDelay(400 / portTICK_RATE_MS);
        LCD_DisplayOn();
        vTaskDelay(400 / portTICK_RATE_MS);
    }
}

void LCD_Init(uint8_t fan_display)
{
    //gpio_bit_reset(RCU_GPIOD, GPIO_PIN_15);
    //log_debug("\r\n === lcd_init ... === \r\n");
    gpio_bit_set(GPIOA, GPIO_PIN_15);
    vTaskDelay(1 / portTICK_RATE_MS);
    gpio_bit_reset(GPIOA, GPIO_PIN_15);
    vTaskDelay(10 / portTICK_RATE_MS);
    gpio_bit_set(GPIOA, GPIO_PIN_15);
    vTaskDelay(240 / portTICK_RATE_MS);
    LCD_WR_REG(0x11);     //Sleep out
    vTaskDelay(150 / portTICK_RATE_MS);
    LCD_WR_REG(0xB1);     //In normal mode
    LCD_WR_DATA(0x00);   //frame rate=85.3Hz
    LCD_WR_DATA(0x2C);
    LCD_WR_DATA(0x2B);
    LCD_WR_REG(0xB2);     //In Idle mode
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x01);
    LCD_WR_REG(0xB3);     //In partial mode
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x01);
    LCD_WR_DATA(0x01);
    LCD_WR_REG(0xB4);     //DOT inversion Display Inversion Control
    LCD_WR_DATA(0x03);
    /*LCD_WR_REG(0xB9);     //In normal mode
    LCD_WR_DATA(0xFF);
    LCD_WR_DATA(0x83);
    LCD_WR_DATA(0x47);*/
    LCD_WR_REG(0xC0);     //VRH: Set the GVDD
    LCD_WR_DATA(7 << 5 | 0x1F);
    LCD_WR_DATA(0x1f);
    LCD_WR_DATA(0x84);
    LCD_WR_REG(0xC1);     //set VGH/ VGL
    LCD_WR_DATA(0x05);   //??02 VGH=16.6 VGL=-7.5  00 VGH=11.6 VGL=-7.5  06 VGH=16.6  VGL=-10
    LCD_WR_REG(0xC2);     //APA: adjust the operational amplifier DCA: adjust the booster Voltage
    LCD_WR_DATA(0xce);
    //LCD_WR_DATA(0x00);
    LCD_WR_REG(0xC3);     //In Idle mode (8-colors)
    LCD_WR_DATA(0x8A);
    LCD_WR_DATA(0x2A);
    LCD_WR_REG(0xC4);     //In partial mode + Full color
    LCD_WR_DATA(0x8A);
    LCD_WR_DATA(0xEE);
    LCD_WR_REG(0xC5);     //In partial mode + Full color
    LCD_WR_DATA(0x0e);
    //LCD_WR_REG(0xC5);     //VCOM
    //LCD_WR_DATA(0x09);
    //LCD_WR_REG(0x21);     //Display inversion
    //LCD_WR_DATA(0);
    LCD_WR_REG(0xC7);
    LCD_WR_DATA(0x10);
    LCD_WR_REG(0x36);     //MX, MY, RGB mode
    LCD_WR_DATA(0xC0); //08
    LCD_WR_REG(0xE0);
    LCD_WR_DATA(0x0C);
    LCD_WR_DATA(0x1C);
    LCD_WR_DATA(0x1B);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x2F);
    LCD_WR_DATA(0x28);
    LCD_WR_DATA(0x20);
    LCD_WR_DATA(0x24);
    LCD_WR_DATA(0x23);
    LCD_WR_DATA(0x22);
    LCD_WR_DATA(0x2A);
    LCD_WR_DATA(0x36);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x05);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x10);
    LCD_WR_REG(0xE1);
    LCD_WR_DATA(0x0C);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x1A);
    LCD_WR_DATA(0x2E);
    LCD_WR_DATA(0x27);
    LCD_WR_DATA(0x21);
    LCD_WR_DATA(0x24);
    LCD_WR_DATA(0x24);
    LCD_WR_DATA(0x22);
    LCD_WR_DATA(0x2A);
    LCD_WR_DATA(0x35);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x05);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x10);
    LCD_WR_REG(0x35);     //65k mode
    LCD_WR_DATA(0x00);
    LCD_WR_REG(0x3A);     //65k mode
    LCD_WR_DATA(0x05);
    LCD_WR_REG(0x2f);
    LCD_WR_REG(0xB6);
    LCD_WR_REG(0xEB);
    LCD_WR_REG(0x81);
    LCD_WR_REG(0x29);     //Display on
    LCD_WR_REG(0x26);     //
    LCD_WR_DATA(0x08);

    if(fan_display) {
        LCD_WR_REG(0x21);    //inversion
    }

    //LCD_WR_REG(0x39);
    //LCD_WR_REG(0x3A);
    //LCD_WR_DATA(0x05);
    LCD_Display_Dir(0);             //????
    LCD_Clear(BLACK);     //??
    vTaskDelay(100 / portTICK_RATE_MS);
#ifdef LCD_PWM_BL
    BL_PWM_CTRL_ON;
    bl_pwm_ctrl_on();
#else
    BL_CTRL_ON;
#endif
    //log_debug("\r\n Display on \r\n");
}

void lcd_init(void)
{
    LCD_Init(0);
    //main_test((uint8_t *)"IC:ST7735");
}
void test_show(void)
{
    //static uint8_t ii = 0;
    //LCD_Clear(0x0177);
    //LCD_Clear(BLACK); vTaskDelay(1 / portTICK_RATE_MS);
    /*LCD_WR_REG(0x33);//SCRLAR
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x30);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x40);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x30);

    LCD_WR_REG(0x2A);//column
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x10);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x4A);

    LCD_WR_REG(0x2B);//row
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x20);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x4A);


    LCD_WR_REG(0x37);//scroll
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x06);*/
    XY_SIZE_T xy;
    xy.w = 0x80;
    xy.h = 0xA0;
    xy.x = (128 - xy.w) / 2;
    xy.y = 0;
    /*if(ii == 0) {
        Gui_Drawbmp16_2(&xy, gImage_test4);

    } else if(ii == 1) {*/
    Gui_Drawbmp16_2(&xy, gImage_test16);
    /*} else if(ii == 2) {
        Gui_Drawbmp16_2(&xy, gImage_test10);

    } else if(ii == 3) {
        //Gui_Drawbmp16_2(&xy, gImage_test4);
    }

    ii++;*/
    //Gui_Drawbmp16_2(&xy, gImage_222b);
}
uint8_t music_show_view = 0;
static uint8_t first_guide_show = 0;

void shengri_reminder(void)
{
    //DrawPage("温馨提示", BLUE);
    music_show_view = 0;
    first_guide_show = 0;
    //LCD_Clear(BLACK);
    LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
#if 1
    XY_SIZE_T xy;
    xy.w = 0x80;
    xy.h = 0x2B;
    xy.x = 0;//(128 - xy.w) / 2;
    xy.y = 160 - xy.h;
    Gui_Drawbmp16_2(&xy, gImage_bg_bottom);
    /*xy.w = 0x5b;
    xy.h = 0x5b;
    xy.x = (128 - 0x5b) / 2;
    xy.y = 0;
    Gui_Drawbmp16_2(&xy, gImage_shengri);*/
    xy.w = 0x50;
    xy.h = 0x48;
    xy.x = (128 - xy.w) / 2;
    xy.y = 12;
    Gui_Drawbmp16_2(&xy, gImage_shengri);
    POINT_COLOR = WHITE;
    //POINT_COLOR = 0X053f;//MK_COLOR(2,2,31);//DEBUG_COLOR1;//0x17E1;//YELLOW;
    //Show_Str(0, 96, "祝您在新的一岁里", 16, 1);
    //Show_Str(0, 116, "，身体健康，万事", 16, 1);
#ifdef ENGLISH_VERSION
    Show_Str(8, 90, "happy birthday", 16, 1);
    //Show_Str(16, 96, "birthday", 16, 1);
#elif defined(ITALIAN_VERSION)
    //#error()
    Show_Str(6, 90, "buon compleanno", 16, 1);
#elif defined(ESPANOL_VERSION)
    Show_Str(6 + 6, 86, "Feliz cumplea", 16, 1);
    Show_spain_Str(6 + 16, 86 + 16, "ñ", 8, 1);
    Show_Str(6 + 8 + 16, 86 + 16, "os a ti", 16, 1);
#else
    Show_Str(32, 100, "生日快乐", 16, 1);
#endif
#endif
#if 0
    Guide_distance = 204; //for test
    LCD_ShowNum(128 / 2 - 32, 130, 3, 1, 16);
    //LCD_ShowNum(128/2-32+16, 130, Guide_distance%100/10, 1, 16);
    //LCD_ShowNum(128/2-32+32, 130, Guide_distance%10, 1, 16);
#endif
    //Pic_test();
#ifdef DEBUG_PRINTF
    char* p = "车";
    char* po = "í";
    //log_debug("shengri= %x%x%x %x%x\n",*p,*(p+1),*(p+2),*po,*(po+1));
#endif
}

void baoyang_note(void)
{
    //DrawPage("重要提醒", BLACK);
    //LCD_Clear(BLACK);
    music_show_view = 0;
    first_guide_show = 0;
    LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    //xy.w = 0x80;
    //xy.h = 0x2B;
    //xy.x = 0;//(128 - xy.w) / 2;
    //xy.y = 160 - xy.h;
    //Gui_Drawbmp16_2(&xy, gImage_bg_bottom);
    /*xy.w = 0x5b;
    xy.h = 0x5b;
    xy.x = (128 - 0x5b) / 2;
    xy.y = 0;
    Gui_Drawbmp16_2(&xy, gImage_shengri);*/
    xy.w = 0x53;
    xy.h = 0x4C;
    xy.x = (128 - xy.w) / 2;
    xy.y = 12;
    Gui_Drawbmp16_2(&xy, gImage_baoyang);
    POINT_COLOR = WHITE;//DEBUG_COLOR2;
#ifdef ENGLISH_VERSION
    Show_Str(24 + 8, 86, "Regular", 16, 1);
    Show_Str(16, 100, "Maintenance", 16, 1);
#elif defined(ITALIAN_VERSION)
    Show_Str(16, 86, "Manutenzione", 16, 1);
    Show_Str(16 + 8, 100, "dei veicoli", 16, 1);
#elif defined(ESPANOL_VERSION)
    Show_Str(16 - 4, 86, "Mantenimiento", 16, 1);
    Show_Str(16 + 8 - 8, 100, "de veh", 16, 1);
    Show_spain_Str(16 + 48 + 8 - 8, 100, "í", 8, 1);
    Show_Str(16 + 8 + 48 + 8 - 8, 100, "culos", 16, 1);
#else
    Show_Str(16 + 16, 98, "定期保养", 16, 1);
#endif
    //Show_Str(40, 101, "期保养", 16, 1);
    //Show_Str(0, 136, "骑行乐趣！", 16, 1);
}

void jihuo_note(void)
{
    //DrawPage("重要提醒", BLACK);
    //LCD_Clear(0x0177);
    //LCD_Clear(BLACK);
    music_show_view = 0;
    first_guide_show = 0;
    LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    xy.w = 0x80;
    xy.h = 0x2B;
    xy.x = 0;//(128 - xy.w) / 2;
    xy.y = 160 - xy.h;
    //Gui_Drawbmp16_2(&xy, gImage_bg_bottom);
    /*xy.w = 0x5b;
    xy.h = 0x5b;
    xy.x = (128 - 0x5b) / 2;
    xy.y = 0;
    Gui_Drawbmp16_2(&xy, gImage_shengri);*/
    xy.w = 0x52;
    xy.h = 0x47;
    xy.x = (128 - xy.w) / 2;
    xy.y = 12;
    Gui_Drawbmp16_2(&xy, gImage_jihuo);
    //POINT_COLOR = DEBUG_COLOR3;
    POINT_COLOR = WHITE;
    //Show_Str(0, 96, "您的车辆使用服务", 16, 1);
#ifdef ENGLISH_VERSION
    Show_Str(20, 84, "Activation", 16, 1);
    Show_Str(20, 100, "Successful", 16, 1);
#elif defined(ITALIAN_VERSION)
    Show_Str(20, 84, "Attivazione", 16, 1);
    Show_Str(20 + 16, 100, "riuscita", 16, 1);
#elif defined(ESPANOL_VERSION)
    Show_Str(20 + 10, 84, "Activado", 16, 1);
    Show_Str(20 + 8, 100, "con ", 16, 1);
    Show_spain_Str(20 + 32 + 8, 100, "é", 8, 1);
    Show_Str(20 + 40 + 8, 100, "xito", 16, 1);
#else
    Show_Str(24, 96, "已成功激活", 16, 1);
#endif
    //Show_Str(0, 136, "您的信任！", 16, 1);
}
void boot_logo1()
{
    //DrawPage("重要提醒", BLACK);
    LCD_Clear(BLACK);
    //LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    music_show_view = 0;
    first_guide_show = 0;
    xy.w = 0x53;
    xy.h = 0x4f;
    xy.x = (128 - xy.w) / 2;
    xy.y = (160 - xy.h) / 2;
    Gui_Drawbmp16_2(&xy, gImage_1);
    POINT_COLOR = WHITE;//DEBUG_COLOR3;
}
void boot_logo2()
{
    //DrawPage("重要提醒", BLACK);
    //LCD_Clear(BLACK);
    //LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    music_show_view = 0;
    first_guide_show = 0;
    xy.w = 0x55;
    xy.h = 0x54;
    xy.x = (128 - xy.w) / 2;
    xy.y = (160 - xy.h) / 2;
    Gui_Drawbmp16_2(&xy, gImage_2);
    POINT_COLOR = WHITE;//DEBUG_COLOR3;
}
void boot_logo3()
{
    //DrawPage("重要提醒", BLACK);
    //LCD_Clear(BLACK);
    //LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    music_show_view = 0;
    first_guide_show = 0;
    xy.w = 0x55;
    xy.h = 0x54;
    xy.x = (128 - xy.w) / 2;
    xy.y = (160 - xy.h) / 2;
    Gui_Drawbmp16_2(&xy, gImage_3);
    POINT_COLOR = WHITE;//DEBUG_COLOR3;
}
void boot_logo4()
{
    //DrawPage("重要提醒", BLACK);
    //LCD_Clear(BLACK);
    //LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    music_show_view = 0;
    first_guide_show = 0;
    xy.w = 0x55;
    xy.h = 0x54;
    xy.x = (128 - xy.w) / 2;
    xy.y = (160 - xy.h) / 2;
    Gui_Drawbmp16_2(&xy, gImage_4);
    POINT_COLOR = WHITE;//DEBUG_COLOR3;
}



void daoqi_note(void)
{
    //DrawPage("重要提醒", BLACK);
    //LCD_Clear(BLACK);
    LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    music_show_view = 0;
    first_guide_show = 0;
    //xy.w = 0x80;
    //xy.h = 0x2B;
    //xy.x = 0;//(128 - xy.w) / 2;
    //xy.y = 160 - xy.h;
    //Gui_Drawbmp16_2(&xy, gImage_bg_bottom);
    /*xy.w = 0x5b;
    xy.h = 0x5b;
    xy.x = (128 - 0x5b) / 2;
    xy.y = 0;
    Gui_Drawbmp16_2(&xy, gImage_shengri);*/
    xy.w = 0x52;
    xy.h = 0x47;
    xy.x = (128 - xy.w) / 2;
    xy.y = 12;
    Gui_Drawbmp16_2(&xy, gImage_daoqi);
    POINT_COLOR = WHITE;//DEBUG_COLOR3;
    //Show_Str(16, 74 + 6, "您的车辆使用", 16, 1);
#ifdef ENGLISH_VERSION
    Show_Str(24 + 8, 84, "Service", 16, 1);
    Show_Str(16, 100, "has expired", 16, 1);
#elif defined(ITALIAN_VERSION)
    Show_Str(24 + 8, 84, "Scadenza", 16, 1);
    Show_Str(16, 100, "del servizio", 16, 1);
#elif defined(ESPANOL_VERSION)
    Show_Str(16 + 6, 84, "Vencimiento ", 16, 1);
    Show_Str(16, 100, "del servicio", 16, 1);
#else
    Show_Str(24, 94, "服务已到期", 16, 1);
#endif
    //if(show_time_update){
    show_time(2);
    //}
    //Show_Str(0, 88, "已到期，请提前做", 16, 1);
    //Show_Str(0, 108, "好续费或调整计划", 16, 1);
}
void display_tel_num(uint8_t incoming)
{
    uint8_t i;
    //LCD_Clear(WHITE);
    BACK_COLOR = (BLACK);;
    POINT_COLOR = YELLOW;
    music_show_view = 0;
    first_guide_show = 0;
    music_show_view = 0;
    first_guide_show = 0;

    for(i = 0; i < TEL_LEN; i++) {
        if(phone_t.tel_num[7 + i] == 0) {
            break;
        }

        if(incoming) {
            LCD_ShowNum(20 + (i % 16) * 8, 94 + (i / 16) * 16, phone_t.tel_num[i + 7] - '0', 1, 16);

        } else {
            LCD_ShowNum(20 + (i % 16) * 8, 94 + (i / 16) * 16, phone_t.tel_num[i + 7] - '0', 1, 16);
            //LCD_ShowNum(20 + (i % 16) * 8, 130 + (i / 16) * 16, phone_t.tel_num[i + 7] - '0', 1, 16);
        }
    }

    uint8_t name[5][7] = {"Uknown", "Deng", "Zhou", "Li", "Test"};
    uint8_t index = 0;
    log_debug("%d-\n", i, &(phone_t.tel_num[7]));

    if(memcmp(&(phone_t.tel_num[7]), "13617649791", i) == 0) {
        index = 1;

    } else if(memcmp(&(phone_t.tel_num[7]), "13108918732", i) == 0) {
        index = 2;

    } else if(memcmp(&(phone_t.tel_num[7]), "13530292292", i) == 0) {
        index = 3;

    } else if(memcmp(&(phone_t.tel_num[7]), "16623629967", i) == 0) {
        index = 4;
    }

    //LCD_ShowString();
    LCD_ShowString(10, 80 - 4, 80, 12, 16, name[index]);
    //index++;
    //if(index==3)index=0;
}

void display_tel_call(uint8_t incoming)
{
    //LCD_Clear(BLACK);
    music_show_view = 0;
    first_guide_show = 0;
    LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
    XY_SIZE_T xy;
    xy.w = 0x80;
    xy.h = 0x2B;
    xy.x = 0;//(128 - xy.w) / 2;
    xy.y = 160 - xy.h;
    //Gui_Drawbmp16_2(&xy, gImage_bg_bottom);
    xy.w = 0x4d;
    xy.h = 0x45;
    xy.x = (128 - xy.w) / 2;
    xy.y = 12;
    Gui_Drawbmp16_2(&xy, gImage_imcoming);
    //Gui_Drawbmp16_2(&xy, gImage_laidian);
    display_tel_num(incoming);
}
void display_outgo()
{
    display_tel_call(0);
    //Show_Str(128 / 2 - 16, 110, "去电", 16, 1);
}
void display_incom()
{
    display_tel_call(1);
    //Show_Str(128 / 2 - 16, 130, "来电", 16, 1);
}

void show_time(uint8_t h)
{
    uint8_t i = 0;
#if 0
    POINT_COLOR = WHITE;
    BACK_COLOR = BLACK;
    h = 160 - 34;

    if(no_rtc) {
        return;
    }

    //LCD_ShowNum(0 + (i % 16) * 8, h, calendar.w_year, 2, 16);
    i++;
    i++;
#ifdef ENGLISH_VERSION

    if(calendar.mon == 1) {
        Show_Str(6 + (i % 16) * 8, h, "Jan",  16, 0);

    } else if(calendar.mon == 2) {
        Show_Str(6 + (i % 16) * 8, h, "Feb",  16, 0);

    } else if(calendar.mon == 3) {
        Show_Str(6 + (i % 16) * 8, h, "Mar",  16, 0);

    } else if(calendar.mon == 4) {
        Show_Str(6 + (i % 16) * 8, h, "Apr",  16, 0);

    } else if(calendar.mon == 5) {
        Show_Str(6 + (i % 16) * 8, h, "May",  16, 0);

    } else if(calendar.mon == 6) {
        Show_Str(6 + (i % 16) * 8, h, "Jun",  16, 0);

    } else if(calendar.mon == 7) {
        Show_Str(6 + (i % 16) * 8, h, "Jul",  16, 0);

    } else if(calendar.mon == 8) {
        Show_Str(6 + (i % 16) * 8, h, "Aug",  16, 0);

    } else if(calendar.mon == 9) {
        Show_Str(6 + (i % 16) * 8, h, "Sep",  16, 0);

    } else if(calendar.mon == 10) {
        Show_Str(6 + (i % 16) * 8, h, "Oct",  16, 0);

    } else if(calendar.mon == 11) {
        Show_Str(6 + (i % 16) * 8, h, "Nov",  16, 0);

    } else if(calendar.mon == 12) {
        Show_Str(6 + (i % 16) * 8, h, "Dec",  16, 0);
    }

    i++;
    i++;
#elif defined(ITALIAN_VERSION)

    if(calendar.mon == 1) {
        Show_Str(6 + (i % 16) * 8, h, "Gen",  16, 0);

    } else if(calendar.mon == 2) {
        Show_Str(6 + (i % 16) * 8, h, "Feb",  16, 0);

    } else if(calendar.mon == 3) {
        Show_Str(6 + (i % 16) * 8, h, "Mar",  16, 0);

    } else if(calendar.mon == 4) {
        Show_Str(6 + (i % 16) * 8, h, "Apr",  16, 0);

    } else if(calendar.mon == 5) {
        Show_Str(6 + (i % 16) * 8, h, "May",  16, 0);

    } else if(calendar.mon == 6) {
        Show_Str(6 + (i % 16) * 8, h, "Giu",  16, 0);

    } else if(calendar.mon == 7) {
        Show_Str(6 + (i % 16) * 8, h, "Lug",  16, 0);

    } else if(calendar.mon == 8) {
        Show_Str(6 + (i % 16) * 8, h, "Ago",  16, 0);

    } else if(calendar.mon == 9) {
        Show_Str(6 + (i % 16) * 8, h, "Set",  16, 0);

    } else if(calendar.mon == 10) {
        Show_Str(6 + (i % 16) * 8, h, "Ott",  16, 0);

    } else if(calendar.mon == 11) {
        Show_Str(6 + (i % 16) * 8, h, "Nov",  16, 0);

    } else if(calendar.mon == 12) {
        Show_Str(6 + (i % 16) * 8, h, "Dic",  16, 0);
    }

    i++;
    i++;
#elif defined(ESPANOL_VERSION)

    if(calendar.mon == 1) {
        Show_Str(6 + (i % 16) * 8, h, "Jan",  16, 0);

    } else if(calendar.mon == 2) {
        Show_Str(6 + (i % 16) * 8, h, "Feb",  16, 0);

    } else if(calendar.mon == 3) {
        Show_Str(6 + (i % 16) * 8, h, "Mar",  16, 0);

    } else if(calendar.mon == 4) {
        Show_Str(6 + (i % 16) * 8, h, "Apr",  16, 0);

    } else if(calendar.mon == 5) {
        Show_Str(6 + (i % 16) * 8, h, "May",  16, 0);

    } else if(calendar.mon == 6) {
        Show_Str(6 + (i % 16) * 8, h, "Jun",  16, 0);

    } else if(calendar.mon == 7) {
        Show_Str(6 + (i % 16) * 8, h, "Jul",  16, 0);

    } else if(calendar.mon == 8) {
        Show_Str(6 + (i % 16) * 8, h, "Aug",  16, 0);

    } else if(calendar.mon == 9) {
        Show_Str(6 + (i % 16) * 8, h, "Sep",  16, 0);

    } else if(calendar.mon == 10) {
        Show_Str(6 + (i % 16) * 8, h, "Oct",  16, 0);

    } else if(calendar.mon == 11) {
        Show_Str(6 + (i % 16) * 8, h, "Nov",  16, 0);

    } else if(calendar.mon == 12) {
        Show_Str(6 + (i % 16) * 8, h, "Dec",  16, 0);
    }

    i++;
    i++;
#else
    LCD_ShowNum(6 + (i % 16) * 8, h, calendar.mon, 2, 16);
    i++;
    i++;
    Show_Str(6 + (i % 16) * 8, h, "月", 16, 0);
#endif
    i++;
    i++;
    LCD_ShowNum(6 + (i % 16) * 8, h, calendar.mday, 2, 16);
    i++;
    i++;
#ifdef ENGLISH_VERSION
    LCD_ShowNum(6 + (i % 16) * 8 + 8, h, calendar.year + 2000, 4, 16);
#elif defined(ITALIAN_VERSION)
    LCD_ShowNum(6 + (i % 16) * 8 + 8, h, calendar.year + 2000, 4, 16);
#elif defined(ESPANOL_VERSION)
    LCD_ShowNum(6 + (i % 16) * 8 + 8, h, calendar.year + 2000, 4, 16);
#else
    Show_Str(6 + (i % 16) * 8, h, "日", 16, 0);
    LCD_ShowNum(6 + (i % 16) * 8 + 8, h, calendar.year + 2000, 4, 16);
#endif
    //i++;
    i -= 3;
    //i++;
    //i++;
    LCD_ShowNum(0 + (i % 16) * 8, h + 16, calendar.hour, 2, 16);
    i++;
    i++;
    LCD_ShowChar(0 + (i % 16) * 8, h + 16, ':', 16, 1);
    i++;
    LCD_ShowNum(0 + (i % 16) * 8, h + 16, calendar.min, 2, 16);
    i++;
    i++;
    LCD_ShowChar(0 + (i % 16) * 8, h + 16, ':', 16, 1);
    i++;
    LCD_ShowNum(0 + (i % 16) * 8, h + 16, calendar.sec, 2, 16);
    i++;
    i++;
    show_time_update = 0;
    //i++;i++;
#endif
}

void show_votage(void)
{
    static float pre_f12v_in_ref;

    if(f12v_in_ref != pre_f12v_in_ref) {
        pre_f12v_in_ref = f12v_in_ref;

    } else {
        return;
    }

    //LCD_ShowNum(10, 50, (uint32_t)f12v_in_ref, 2, 16);
    //LCD_ShowChar(26, 50, '.', 16, 0);
    //LCD_ShowNum(32, 50, ((uint32_t)(f12v_in_ref * 100) % 100), 2, 16);
    //LCD_ShowChar(48, 50, 'v', 16, 0);
}

void lcd_display()
{
    uint8_t i, j;
#if 0
    //LCD_Clear(BLACK);
    Color_Test();                           //纯色测试
    //Read_Test();                              //读屏测试
    FillRec_Test();                         //图形测试
    English_Font_test();                //英文测试
    Chinese_Font_test();
    Pic_test();                                 //图片测试
    /*static uint16_t x,y;
    x +=4 ;
    y+=5;
    POINT_COLOR=GREEN+0x104;
    LCD_DrawPoint(x,y);*/
    Switch_test();                          //显示开关测试
    Rotate_Test();
#endif
    //DrawTestPage("中文显示");
    //Color_Test();
    /*uint32_t totalpoint=lcddev.width;
    totalpoint*=lcddev.height;          //得到总点数
    LCD_SetCursor(0x00,0x0000); //设置光标位置
    LCD_WriteRAM_Prepare();             //开始写入GRAM
    LCD_Fill(0,0,lcddev.width,20,BLUE);*/
    //POINT_COLOR=GREEN;
#if 0
    LCD_DrawLine(0, 20, lcddev.width, 20);
    POINT_COLOR = BLUE;
    LCD_DrawLine(0, 21, lcddev.width, 21);
    POINT_COLOR = BRRED;
    LCD_DrawLine(0, 22, lcddev.width, 22);
    //绘制固定栏down
    LCD_Fill(0, lcddev.height - 20, lcddev.width, lcddev.height, BLUE);
    POINT_COLOR = GREEN;
    LCD_DrawLine(0, lcddev.height - 20, lcddev.width, lcddev.height - 20);
    POINT_COLOR = BLUE;
    LCD_DrawLine(0, lcddev.height - 21, lcddev.width, lcddev.height - 21);
    POINT_COLOR = BRRED;
    LCD_DrawLine(0, lcddev.height - 22, lcddev.width, lcddev.height - 22);
    POINT_COLOR = WHITE;
    Gui_StrCenter(0, 2, "中文显示", 10, 1); //居中显示
    Gui_StrCenter(0, lcddev.height - 18, "永达创力电子", 16, 1); //居中显示
    POINT_COLOR = RED;  //画笔颜色
    BACK_COLOR = BLACK; //背景色
    Show_Str(10, 30, "16X16:", 8, 1);
    //Show_Str(10,50,"16X16:   显",16,1);
    //Show_Str(10,70,"24X24:示",24,1);
    //Show_Str(10,100,"32X32:屏",32,1);
    vTaskDelay(20 / portTICK_RATE_MS);
    //gpio_bit_set(GPIOB, GPIO_PIN_15);
    vTaskDelay(1000 / portTICK_RATE_MS);
    //gpio_bit_reset(GPIOB, GPIO_PIN_15);
    //Show_Str(10,50,"16X16:   显",16,1);
    //Show_Str(10,70,"24X24:示",24,1);
    //Show_Str(10,100,"32X32:屏",32,1);
#endif
    Chinese_Font_test();
    return;
    /*do {
        Chinese_Font_test();
        vTaskDelay(1000 / portTICK_RATE_MS);
        Color_Test();
        vTaskDelay(1000 / portTICK_RATE_MS);
        //uint32_t start = xTaskGetTickCount();
        FillRec_Test();
        vTaskDelay(1000 / portTICK_RATE_MS);                         //图形测试
        English_Font_test();
        vTaskDelay(1000 / portTICK_RATE_MS);            //英文测试
        //Chinese_Font_test();vTaskDelay(1000/portTICK_RATE_MS );
        Pic_test();
        vTaskDelay(1000 / portTICK_RATE_MS);
        LCD_Clear(BLACK);
        //uint32_t end = xTaskGetTickCount();
        //log_debug("diff %d\n",end-start);
        vTaskDelay(1000 / portTICK_RATE_MS);
    } while(1);*/
    //end = xTaskGetTickCount();
    //log_debug("diff %d\n",end-start);
    //test_spi();
    //#define FRAME_8BIT
    spi_io_init(SPI_FRAMESIZE_8BIT);
    LCD_SetCursor(20, 20);
    //LCD_WR_REG(lcddev.wramcmd);
    LCD_WriteRAM_Prepare();

    //rcu_periph_clock_enable(RCU_GPIOD);
    do {
        //spi_io_init(SPI_FRAMESIZE_16BIT);
        //SPI_CS_0;
        //SPI_DC_1;
        //LCD_SetCursor(20,20);
        LCD_WriteRAM_Prepare();
        LCD_WriteRAM(RED);
        //LCD_WR_DATA(RED);
        LCD_WriteRAM(RED);
        LCD_WriteRAM(RED);
        //LCD_WriteRAM(RED);
        //LCD_WriteRAM_spi(RED);
        //LCD_WR_DATA_spi(RED);
        LCD_WriteRAM_End;
        //vTaskDelay(1000/portTICK_RATE_MS );
        //SPI_CS_1;
        log_debug("lcd 16\n");
        vTaskDelay(1000 / portTICK_RATE_MS);
    } while(1);

    //SPI_CS_1;
    //Pic_test();
}


void music_view(void)
{
    uint8_t i, show_len;
    XY_SIZE_T xy;
    char buf[32];

    if(music_show_view == 0) {
        music_show_view = 1;
        //LCD_Clear(BLACK);
        LCD_Fill(0, 0, 128, 30, BLACK);
        LCD_Fill(0x1e, 30, 0x2a, 0x44 + 30, BLACK);
        LCD_Fill(0, 160 - 30 - 0x44, 128, 160 - 0x2b, BLACK);
        LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
        xy.w = 0x58;
        xy.h = 0x4a;
        xy.x = (128 - xy.w) / 2;
        xy.y = 0;
        Gui_Drawbmp16_2(&xy, gImage_music);
    }

    ;

    //Show_Str(8, 90, "happy birthday", 16, 1);
    LCD_Fill(0, 84 - 16, 128, 84 - 16 + 48, BLACK);

#ifdef DEBUG_PRINTF
    log_debug("LCD_Fill len=%d\n", music_t.len);

#endif
    if(music_t.len <= 16) {
        for(i = 0; i < music_t.len; i++) {
            if((music_t.blue_buf[i] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 - 16, music_t.blue_buf[i], 16, 1);
            }
        }

    } else if(music_t.len <= 32) {
        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 - 16, music_t.blue_buf[i], 16, 1);
            }
        }

        for(i = 0; i < music_t.len % 16; i++) {
            if((music_t.blue_buf[i + 16] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 90, music_t.blue_buf[i + 16], 16, 1);
            }
        }

    } else if(music_t.len <= 48) {
        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 - 16, music_t.blue_buf[i], 16, 1);
            }
        }

        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i + 16] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84, music_t.blue_buf[i + 16], 16, 1);
            }
        }

        /*  for(i=0;i<music_t.len%16;i++){
                if((music_t.blue_buf[i+32]&0x80)==0)
        LCD_ShowChar(i*8, 90+16, music_t.blue_buf[i+32], 16, 1);
        }*/

    } else if(music_t.len <= 64) {
        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 - 16, music_t.blue_buf[i], 16, 1);
            }
        }

        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i + 16] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84, music_t.blue_buf[i + 16], 16, 1);
            }
        }

        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i + 32] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 + 16, music_t.blue_buf[i + 32], 16, 1);
            }
        }

        /*      for(i=0;i<music_t.len;i++){
                    if((music_t.blue_buf[i+48]&0x80)==0)
            LCD_ShowChar(i*8, 90+32, music_t.blue_buf[i+48], 16, 1);
        }*/

    } else {
        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 - 16, music_t.blue_buf[i], 16, 1);
            }
        }

        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i + 16] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84, music_t.blue_buf[i + 16], 16, 1);
            }
        }

        for(i = 0; i < 16; i++) {
            if((music_t.blue_buf[i + 32] & 0x80) == 0) {
                LCD_ShowChar(i * 8, 84 + 16, music_t.blue_buf[i + 32], 16, 1);
            }
        }

        /*      for(i=0;i<music_t.len;i++){
                    if((music_t.blue_buf[i+48]&0x80)==0)
            LCD_ShowChar(i*8, 90+32, music_t.blue_buf[i+48], 16, 1);
        }*/
    }
}

void music_review(void)
{
    music_show_view = 0;
    music_view();
}


void guide_view(void)
{
    XY_SIZE_T xy;
    char buf[32];
    static uint8_t guide_ico = 0xFF;

    //LCD_Clear(WHITE);
    if(first_guide_show == 0) {
        LCD_Fill(0, 0, 128, 30, BLACK);//up
        LCD_Fill(0x1e, 30, 0x1e + 0x9, 0x44 + 30, BLACK);//left pad
        //LCD_Fill(0, 160 - 30 - 0x44, 128, 160 - 0x2b, BLACK);
        //LCD_Fill(0, 0, 128, 160 - 0x2b, BLACK);
        LCD_Fill(0x1e + 0x9 + 0x32, 30, 0x1e + 0x9 + 0x32 + 0x9, 0x44 + 30, BLACK);//right pad
        //xy.w = 0x80;
        //xy.h = 0x2B;
        //xy.x = 0;//(128 - xy.w) / 2;
        //xy.y = 160 - xy.h;
        //Gui_Drawbmp16_2(&xy, gImage_bg_bottom);
        xy.w = 0x1e;
        xy.h = 0x44;
        xy.x = 0;
        xy.y = 30;
        Gui_Drawbmp16_2(&xy, gImage_road_left);
        xy.w = 0x1e;
        xy.h = 0x44;
        xy.x = (128 - xy.w);
        xy.y = 30;
        Gui_Drawbmp16_2(&xy, gImage_road_right);
        first_guide_show = 1;
        guide_ico = 0xFF;
    }

    //return;

    if(guide != guide_ico) {
        LCD_Fill(0x1e + 9, 30, 0x1e + 9 + 0xA, 0x44 + 30 - 6, BLACK);
        LCD_Fill(0x1e + 9 + 0xa + 0x1E, 30, 0x1e + 9 + 0xA + 0x1e + 0xA, 0x44 + 30 - 6, BLACK);
        LCD_Fill(0x1e + 9 + 0xA, 30 + 0x2b, 0x1e + 9 + 0xa + 0x1E, 0x44 + 30 - 6, BLACK);

        //return;
        switch(guide) {
            case LEFT:
                xy.w = 0x2b;
                xy.h = 0x30;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_left_m);
                guide_ico = LEFT;
                break;

            case RIGHT:
                xy.w = 0x2b;
                xy.h = 0x30;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_right_m);
                guide_ico = RIGHT;
                break;

            case LEFT_FRONT:
                xy.w = 0x22;
                xy.h = 0x2e;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_left_f);
                guide_ico = LEFT_FRONT;
                break;

            case RIGHT_FRONT:
                xy.w = 0x22;
                xy.h = 0x2e;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_right_f);
                guide_ico = RIGHT_FRONT;
                break;

            case LEFT_BACK:
                xy.w = 0x29;
                xy.h = 0x2c;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_left_b);
                guide_ico = LEFT_BACK;
                break;

            case RIGHT_BACK:
                xy.w = 0x29;
                xy.h = 0x2c;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_right_b);
                guide_ico = RIGHT_BACK;
                break;

            case STRAIT:
                xy.w = 0x1e;
                xy.h = 0x2e;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_zhixing);
                guide_ico = STRAIT;
                break;

            case TURN_LEFT:
                xy.w = 0x30;
                xy.h = 0x2b;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_turn_back);
                guide_ico = TURN_LEFT;
                break;

            case ARRIVE_POINT:
                xy.w = 0x2c;
                xy.h = 0x34;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_tujing);
                guide_ico = ARRIVE_POINT;
                break;

            case ENTER_CIRCLE:
                xy.w = 0x32;
                xy.h = 0x2e;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_circle);
                guide_ico = ENTER_CIRCLE;
                break;

            case ARRIVE_END:
                xy.w = 0x2c;
                xy.h = 0x34;
                xy.x = (128 - xy.w) / 2;
                xy.y = 30;
                Gui_Drawbmp16_2(&xy, gImage_end);
                guide_ico = ARRIVE_END;
                break;
        }
    }

    POINT_COLOR = WHITE;
    uint8_t i = 0, j = 0;
    //Guide_distance=105;//for test
    //log_debug("Guide_distance= 0x%x\n",Guide_distance/100);
    //log_debug("Guide_distance= 0x%x\n",Guide_distance%100/10);
    //log_debug("Guide_distance= 0x%x\n",Guide_distance%10);
    BACK_COLOR = BLACK;
#define H_VALUE 0x5C
    //LCD_Fill(0x1e + 12, 0x5c, 0x1e + 12 + 64, 0x5c + 24, BLACK);
    LCD_Fill(0x9, H_VALUE, 128 - 0x9, H_VALUE + 24, BLACK);

    if(guidance_units) {
        if(Guide_distance / 100) {
            LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, Guide_distance / 100, 1, 24);
            j = 1;
            i++;

        } else {
        }

        if(Guide_distance % 100 / 10) {
            LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, Guide_distance % 100 / 10, 1, 24);
            i++;

        } else {
            if(j) {
                LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, 0, 1, 24);
                i++;
            }
        }

        LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, Guide_distance % 10, 1, 24);
        i++;
        //if(guidance_units) {
#ifdef ENGLISH_VERSION
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "M",  16, 1);
#elif defined(ITALIAN_VERSION)
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "M",  16, 1);
#elif defined(ESPANOL_VERSION)
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "M",  16, 1);
#else
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "米", 16, 1);
#endif

    } else {
        if(Guide_distance / 1000) {
            LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, Guide_distance / 1000, 1, 24);
            j = 1;
            i++;

        } else {
        }

        LCD_ShowChar(128 / 2 - 24 + i * 12, H_VALUE, '.', 24, 1);
        i++;

        if(Guide_distance % 1000 / 100) {
            LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, Guide_distance % 1000 / 100, 1, 24);
            i++;

        } else {
            if(j) {
                LCD_ShowNum(128 / 2 - 24 + i * 12, H_VALUE, 0, 1, 24);
                i++;
            }
        }

        //LCD_ShowNum(128 / 2 - 24 + i * 12, 0x5c, Guide_distance % 10, 1, 24);
        //i++;
        //if(guidance_units) {
#ifdef ENGLISH_VERSION
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "KM",  16, 1);
#elif defined(ITALIAN_VERSION)
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "KM",  16, 1);
#elif defined(ESPANOL_VERSION)
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "KM",  16, 1);
#else
        Show_Str(128 / 2 - 12 + i * 12, H_VALUE + 6, "米", 16, 1);
#endif
    }

    //} else {
    //    Show_Str(128 / 2 - 32 + i * 16, 130, "千米", 16, 1);
    //LCD_ShowNum(128/2-32, 130, Guide_distance, 1, 16);
    //}
}

void guide_test(void)
{
    static uint8_t i = 0;
    //uint8_t o ;

    if(i == ANTEROGRADE) {
        i = 0;
    }

    //o = ds3231_read_test();
    guide = LEFT + i;
    Guide_distance += 300;
    Guide_distance &= 0x7FF;

    if(Guide_distance > 999) {
        guidance_units = 0;    //km

    } else {
        guidance_units = 1;    //m
    }

    log_debug("Guide_distance:%d\n", Guide_distance);
    i++;
    guide_view();
}
